package adv7;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Company implements Serializable {
	private String companyName, address, phone;

	private List<Employees> list = new ArrayList<Employees>();
	{// 匿名构造块
		Employees emp = new Employees("张三", "男", "1111", 32);
		Employees emp1 = new Employees("李四", "男", "2222", 18);
		Employees emp2 = new Employees("王五", "男", "3333", 30);
		list.add(emp);
		list.add(emp1);
		list.add(emp2);
		System.out.println("三位创始人加入成功");
	}

	public Company(String companyName, String address, String phone) {
		super();
		this.companyName = companyName;
		this.address = address;
		this.phone = phone;

	}

	// 招聘员工
	public boolean addCompany(Employees e) {
		// boolean flag = false;
		Employees temp = null;
		for (int i = 0; i < list.size(); i++) {
			if (e.getWorkNumber().equals(list.get(i).getWorkNumber())) {
				return false;
			} else {
				temp = e;
			}
		}
		list.add(temp);
		return true;
	}

	// 输出员工信息
	public void show() {
		for (Employees emp : list) {
			System.out.println(emp);
		}
	}

	// 辞退员工
	public boolean dismiss(String num) {
		boolean f = false;
		for (int i = 0; i < list.size(); i++) {
			if (num.equals(list.get(i).getWorkNumber())) {
				list.remove(i);
				f = true;
			}
		}
		return f;
	}

	// 统计人数
	public void count() {
		int count1 = 0;
		for (int i = 0; i < list.size(); i++) {
			count1++;
		}
		System.out.println("公司人数：" + count1);
	}

	public Company() {

	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public void showInfo() {
		System.out.println("公司名称:" + this.companyName);
		System.out.println("公司注册地址:" + this.address);
		System.out.println("公司电话:" + this.phone);
		show();
	}
}
